Skip to content

Port #[link] to the new attribute parsing infrastructure #143193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Jun 29, 2025

Ports link to the new attribute parsing infrastructure for #131229 (comment)

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jun 29, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 30, 2025

☔ The latest upstream changes (presumably #143233) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jul 15, 2025
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer force-pushed the link_rework branch 5 times, most recently from 147aeec to 29b3648 Compare July 15, 2025 22:30
PrintAttribute
)]
#[derive(HashStable_Generic)]
pub enum NativeLibKind {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type was moved here because it is needed for the link attribute and the original location caused a dependency cycle


#[link(name = "bar", import_name_type = "decorated", kind = "raw-dylib")]
#[link(name = "bar", kind = "raw-dylib")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not testing for the invalid attribute, but instead for the link attribute on an extern type. Because attributes are parsed earlier and this attribute was invalid the error blocked the crash from happening. This is true for quite a few other of the test changes as well

@@ -81,8 +81,7 @@
#[export_stable = 1]
//~^ ERROR malformed
#[link]
//~^ ERROR attribute must be of the form
//~| WARN this was previously accepted by the compiler
//~^ ERROR malformed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BREAKING CHANGE 1: A #[link] attribute which is not a list #[link(...)] used to be a warning future error, is now an error. This needs a crater run.

@@ -61,7 +61,7 @@
#![doc = "2400"]
#![cold] //~ WARN attribute should be applied to a function
//~^ WARN this was previously accepted
#![link()] //~ WARN attribute should be applied to an `extern` block
#![link(name = "x")] //~ WARN attribute should be applied to an `extern` block
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BREAKING CHANGE 2: A link attribute applied to an invalid target was not checked for syntactic correctness, it now is. The invalid target remains a warning, but the syntactic corectness is now checked

@JonathanBrouwer
Copy link
Contributor Author

@rustbot ready
r? @jdonszelmann

Needs a crater run

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jul 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@JonathanBrouwer JonathanBrouwer marked this pull request as ready for review July 16, 2025 12:25
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@jdonszelmann
Copy link
Contributor

@bors try @craterbot queue

bors added a commit that referenced this pull request Jul 16, 2025
Port `#[link]` to the new attribute parsing infrastructure

Ports `link` to the new attribute parsing infrastructure for #131229 (comment)

This rework is not yet finished, it is blocked on the `cfg` attribute being finished, since `link` takes a `cfg` attribute as argument

`@rustbot` blocked
@bors
Copy link
Collaborator

bors commented Jul 16, 2025

⌛ Trying commit 6b10a20 with merge 4797991...

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

☀️ Try build successful - checks-actions
Build commit: 4797991 (4797991aa2efb6d658150f10425b3f3b5d10eceb)

@jdonszelmann
Copy link
Contributor

@craterbot queue

@craterbot
Copy link
Collaborator

🚨 Error: failed to parse the command

🆘 If you have any trouble with Crater please ask in t-infra on Zulip
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@jdonszelmann
Copy link
Contributor

@craterbot check oops

@craterbot
Copy link
Collaborator

🚨 Error: failed to parse the command

🆘 If you have any trouble with Crater please ask in t-infra on Zulip
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@jdonszelmann
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-143193 created and queued.
🤖 Automatically detected try build 4797991
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-143193 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-143193 is completed!
📊 628 regressed and 9 fixed (666127 total)
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jul 20, 2025
@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Jul 20, 2025

These are a bunch of real regressions sadly.
As far as I can see, all regressions are caused crates depending on specifically by winit 0.13 and older (7 years+ old version) and glutin 0.6 and older (9 years+ old version). They are using the link attribute as #[link="dl"] which is invalid syntax. The breaking change is caused by "breaking change 1" above, which makes a future error into an error.

I don't think we should break these popular crates, even though they are very old versions.
On the other side, if this is truly a "future error", when will we make this an error? These old versions will likely be used forever by the hundreds of crates that showed up in crater that will never be updated to a modern version of winit/glutin.

Pinging @rust-lang/lang to decide
cc @jdonszelmann

@traviscross traviscross added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang T-lang Relevant to the language team and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 27, 2025
@traviscross
Copy link
Contributor

Thanks, we'll discuss.

Looking at the crater results, it's worth noting that almost all of the breakage is on GH repositories; very few crates on crates.io are broken.

@joshtriplett
Copy link
Member

I wonder, could we ask the winit and glutin folks to upload a new micro version of those past major versions, with the only change being to fix the link syntax?

@JonathanBrouwer
Copy link
Contributor Author

Sounds like a reasonable solution.
Alternatively we could accept specifically #[link="dl"] as a warning and error on all other invalid arguments, I'll leave T-lang to decide what's best

@joshtriplett
Copy link
Member

@JonathanBrouwer Given the age of those crates, I don't think any addition of parsing logic here would be temporary. How much pain would that parsing logic be to handle the link="dl" case indefinitely?

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Jul 30, 2025

@joshtriplett It should be easy, just an extra if statement at the start of the parser where it currently only accepts a list, just a few lines of code.

What should the attribute actually do? Afaik before this PR the attribute is completely ignored, so I propose to keep it that way. I'll double check that this is what happens

@traviscross
Copy link
Contributor

We talked about this in lang triage.

Here's what I'd propose we do. Let's:

  • Take the breaking change for everything except #[link="dl"].
  • For #[link="dl"], this will trigger a deny-by-default FCW (that reports in dependencies).
    • We can decide later, after the FCW has been out there, and based on a new crater run, whether we ever want to break this too.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Jul 31, 2025

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants